home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / os2 / sysb091a.zip / sysbench / src / pmb_dive.c < prev    next >
Text File  |  1996-06-28  |  33KB  |  1,000 lines

  1.  
  2. // SysBench DIVE test module
  3. // made for the warp II beta toolkit. Must probably be modified to run on OS/2 3.0
  4. // corrected bug where paint_rot tried to paint horizontal lines not vertical 28/06/96
  5.  
  6.  
  7. #define INCL_WIN
  8. #define INCL_GPI
  9. #define INCL_DOS
  10. #include <os2.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #define  _MEERROR_H_
  14. #include "mmioos2.h"                   /* It is from MMPM toolkit           */
  15. #include "dive.h"
  16. #include "fourcc.h"
  17. #include "pmb.h"
  18. #include "types.h"
  19.  
  20. #define ID_WINDOW1 8000
  21. #define PMB_DIVE_CLASS "SysBench dive winclass"
  22. #define MIN_DIVE_TIME 10.0
  23. #define MIN_DIVE2_TIME 1.0
  24. #define MIN_MEASURE 0.1
  25. #define MARGINAL 1.1
  26. #define PI 3.14159265358979323846
  27.  
  28. //static HAB  hab;
  29.  
  30. extern double cos(double);
  31. extern double sin(double);
  32. extern void err(char* s);
  33. extern void warn(char* s);
  34. extern void log(char* s);
  35. //extern HAB anchorblock(void);
  36. extern double rtime(void);    // real time in seconds
  37. extern double dtime(void);    // used CPU time in seconds
  38. extern double test_time;
  39.  
  40. void APIENTRY paint_videobw(ULONG unused);
  41. void APIENTRY paint_rot(ULONG unused);
  42. void APIENTRY paint_ms12(ULONG unused);
  43.  
  44. static MRESULT EXPENTRY DiveWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
  45. static void Open(void *paintfun);
  46. static void Close(void);
  47. void end_Win(HDIVE hDive, char *p, HWND hwndClient);
  48. void clr_lines(s32 y, s32 lines);
  49. void disp_lines(u8* buf, s32 y, s32 lines);
  50. _Inline void disp_lines2(u8* src, u8* dest, s32 yin, s32 yout);
  51. _Inline s32 fun(s32 x, double param);
  52.  
  53. static HWND hwndClient = NULLHANDLE;         /* Client area window handle    */
  54. static HWND hwndFrame = NULLHANDLE;          /* Frame window handle          */
  55. static HMQ  hmq;
  56. static ULONG flCreate;                       /* Window creation control flags*/
  57. static HAB bkHab;
  58. static TID paint_tid;
  59. static double result;
  60. static char* framebuf; // the main framebuffer
  61. static DIVE_CAPS dc;
  62. static HDIVE hDive;
  63. static RECTL rect;
  64. static char szName[50];
  65.  
  66. static void Open(void *paintfun) {
  67.   s32 w,h, x,y;
  68.   RECTL rctl, rctlScreen;
  69.   QMSG qmsg;                            /* Message from message queue   */
  70.   hwndClient = NULLHANDLE;         /* Client area window handle    */
  71.   hwndFrame = NULLHANDLE;          /* Frame window handle          */
  72. //  hab = anchorblock();
  73.  
  74.   if ((bkHab = WinInitialize(0)) == 0L) /* Initialize PM     */
  75.     err("Can't get anchor block handle for background thread");
  76.  
  77.   if ((hmq = WinCreateMsgQueue( bkHab, 0 )) == 0L)/* Create a msg queue */
  78.     err("Can't create message queue for graphics test window");
  79.  
  80.   if (!WinRegisterClass(bkHab, (PSZ)PMB_DIVE_CLASS, (PFNWP)DiveWindowProc, 0, 0)) {
  81.     err("DIVE test error: can't register class for child test window");
  82.   }
  83.  
  84.   flCreate = FCF_TASKLIST;
  85.  
  86.   if ((hwndFrame = WinCreateStdWindow(
  87.                HWND_DESKTOP,            /* Desktop window is parent     */
  88.                0,                       /* window styles           */
  89.                &flCreate,               /* Frame control flag           */
  90.                PMB_DIVE_CLASS,    /* Client window class name     */
  91.                "SysBench dive test window",    /* window text               */
  92.                0,                       /* No special class style       */
  93.                (HMODULE)0L,             /* Resource is in .EXE file     */
  94.                ID_WINDOW1,               /* Frame window identifier      */
  95.                &hwndClient              /* Client window handle         */
  96.                )) == 0L)
  97.     err("Can't create dive test window");
  98.  
  99.   WinQueryWindowRect(HWND_DESKTOP, &rect);
  100.   WinSetWindowPos(hwndFrame, HWND_TOP, rect.xLeft, rect.yBottom,
  101.     rect.xRight-rect.xLeft+1, rect.yTop-rect.yBottom+1, SWP_SIZE | SWP_MOVE | SWP_ACTIVATE | SWP_SHOW | SWP_ZORDER);
  102.  
  103.   DosCreateThread(&paint_tid, (PFNTHREAD)paintfun, 0, 0, 64000);
  104.   while( WinGetMsg( bkHab, &qmsg, 0L, 0, 0 ) )
  105.     WinDispatchMsg( bkHab, &qmsg );
  106. }
  107.  
  108. static void Close(void) {
  109.   WinDestroyWindow(hwndFrame);           /* Tidy up...                   */
  110.   WinDestroyMsgQueue( hmq );             /* Tidy up...                   */
  111.   WinTerminate(bkHab);
  112. }
  113.  
  114. double pmb_dive_bw(void) {
  115.   Open((void*)paint_videobw);
  116.   Close();
  117.   return result;
  118. }
  119.  
  120. double pmb_dive_rot(void) {
  121.   Open((void*)paint_rot);
  122.   Close();
  123.   return result;
  124. }
  125.  
  126. double pmb_dive_ms11(void) {
  127.   Open((void*)paint_ms12);
  128.   Close();
  129.   return result;
  130. }
  131.  
  132. static MRESULT EXPENTRY
  133. DiveWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
  134. {
  135.   switch( msg )
  136.   {
  137.     case WM_CREATE:
  138.       break;
  139.  
  140.     case WM_COMMAND:
  141.       break;
  142.  
  143.     case WM_ERASEBACKGROUND:
  144.       return (MRESULT)( FALSE ); // TRUE -> yes, erase the background
  145.  
  146.     case WM_PAINT:
  147.       {
  148.         HPS    hps;
  149.         RECTL  rc;
  150.         POINTL pt;
  151.  
  152.         hps = WinBeginPaint( hwnd, 0L, &rc );
  153.         GpiSetColor( hps, CLR_BLACK );      // colour of the text,
  154.         GpiSetBackColor( hps, CLR_BLACK );   // its background and
  155.         GpiSetBackMix( hps, BM_OVERPAINT );  // how it mixes,
  156.         GpiSetMix( hps, FM_OVERPAINT );  // how it mixes,
  157. //        WinFillRect(hps, &rc, CLR_BLACK);
  158.         WinEndPaint( hps );                  // Drawing is complete
  159.         break;
  160.       }
  161.     case WM_CLOSE:
  162.       WinPostMsg( hwnd, WM_QUIT, (MPARAM)0,(MPARAM)0 );
  163.       break;
  164.     default:
  165.       return WinDefWindowProc( hwnd, msg, mp1, mp2 );
  166.   }
  167.   return (MRESULT)FALSE;
  168. }
  169.  
  170. void APIENTRY paint_videobw(ULONG unused) {
  171.   HPS hps;
  172.   POINTL p1, p2;
  173.   double t1, t2, test_time;
  174.   RECTL rc;
  175.   PVOID apa;
  176.   ULONG ret;
  177.   PDIVE_CAPS pdc;
  178.   s32 i, j, c, runs, runs_10, framesize, sh, scanlen, frames, numApertures, ApertureNum, Datalen, Offset, ApertureOffset, RemainLen, z;
  179.   char* framecopy;
  180.   char* framecopy1;
  181.   APIRET rc1 = 0UL;
  182.  
  183.   memset(&dc, 0, sizeof(dc));
  184.   dc.ulStructLen = sizeof(dc);
  185.   dc.ulFormatLength = 0;
  186.   ret = DiveQueryCaps(&dc, DIVE_BUFFER_SCREEN);
  187.   if (DIVE_SUCCESS != ret) {
  188.     if (ret == DIVE_ERR_INSUFFICIENT_LENGTH) {
  189.       dc.pFormatData = calloc(dc.ulFormatLength,1);
  190.       ret = DiveQueryCaps(&dc, DIVE_BUFFER_SCREEN); // let's try again
  191.       if (DIVE_SUCCESS != ret) {
  192.         err("Error in call to DiveQueryCaps()");
  193.       }
  194.     } else {
  195.       err("Error in call to DiveQueryCaps()");
  196.     }
  197.   }
  198.  
  199.   rc1 = DiveOpen(&hDive, FALSE, &apa);
  200.  
  201.   if (rc1 != DIVE_SUCCESS)
  202.      {
  203.      if (rc1 == DIVE_ERR_TOO_MANY_INSTANCES)
  204.         {
  205.         log("Dive error - too many instances");
  206.         result = -1;
  207.         }
  208.      if (rc1 == DIVE_ERR_SSMDD_NOT_INSTALLED)
  209.         {
  210.         log("Dive error - SSMDD.SYS not installed");
  211.         result = -1;
  212.         }
  213.      if (rc1 == DIVE_ERR_NO_DIRECT_ACCESS)
  214.         {
  215.         log("Dive error - no direct access");
  216.         result = -1;
  217.         }
  218.      if (rc1 == DIVE_ERR_ALLOCATION_ERROR)
  219.         {
  220.         log("Dive error - allocation error, check MMOS/2 installed");
  221.         result = -1;
  222.         }
  223.      if (rc1 != DIVE_SUCCESS)
  224.         {
  225.         result = -1;
  226.         free(dc.pFormatData);
  227.         WinPostMsg( hwndClient, WM_QUIT, (MPARAM)0,(MPARAM)0 );
  228.         return;
  229.          }
  230.   }
  231.  
  232.   framebuf = (char*)apa;
  233.  
  234.   WinQueryWindowRect(HWND_DESKTOP, &rect);
  235.      ret = DiveAcquireFrameBuffer(hDive, &rect);
  236.      if (ret != DIVE_SUCCESS)
  237.         {
  238.         log("Error in DiveAcquireFrameBuffer()");
  239.         result = -1;
  240.         end_Win(hDive,dc.pFormatData,hwndClient);
  241.         return;
  242.         }
  243.  
  244.   framesize = dc.ulVerticalResolution * dc.ulScanLineBytes;
  245.   framecopy = malloc(framesize);
  246.   if (framecopy == null) {
  247.     log("Can't get memory for copy of frame buffer");
  248.     result = -1;
  249.     end_Win(hDive,dc.pFormatData,hwndClient);
  250.     return;
  251.   }
  252.  
  253.   if (dc.fScreenDirect)
  254.      {                                                /* if direct access allowed */
  255.      if (dc.ulApertureSize >= framesize)
  256.         {                    /* and if video buffer larger or equal to our buffer */
  257.         memcpy(framecopy, framebuf, framesize); /* copy from video buffer to ours */
  258.         }
  259.      else
  260.         {